﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.SqlServer.Server;
using Microsoft.Practices.Unity;
using System.Configuration;

namespace SimpleLoggingForNet.Core
{
    internal class DataAccessLayer
    {
        internal static int LogException(string ExceptionCategory, int EventID, string ExceptionMessage, string ExceptionTitle, int ExceptionSeverity, string WorkStationID)
        {
            string sql = "INSERT INTO dbo.Exception ([ID],[ExceptionCategory],[EventID],[ExceptionMessage],[ExceptionSeverity],[ExceptionTitle],[ExceptionApplicationID],[HostID],[ExceptionTimestamp])VALUES(NEWID(),1," + EventID.ToString() + ",'" + ExceptionMessage + "'," + ExceptionSeverity + "," + "'" + ExceptionTitle + "','93DD98EB-6C4E-4AB2-8FA6-4B35E0D456E2','" + WorkStationID + "',GETDATE())";
            int ret = -1;
            try
            {
                SqlDatabase db = new SqlDatabase(ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString);
                ret = db.ExecuteNonQuery(System.Data.CommandType.Text, sql);
            }

            catch (Exception ex)
            {
                string msg = ex.Message;              
            }

            return ret;
        }
    }
}
